#include "unp.h"

void client(int,int) , server(int,int);

int main(int argc ,char *argv[])
{
    int pipe1[2],pipe2[2];
    pid_t childpid;
   
    if(pipe(pipe1) == -1 || pipe(pipe2) == -1) {
       err_sys("pipe1 errror");
    }

    if((childpid=fork()) ==-1)
    {
       err_sys("fork error");
    }else if(childpid == 0){ //child
       close(pipe1[1]);
       close(pipe2[0]);
       
       server(pipe1[0],pipe2[1]);
       exit(0);
    }

    close(pipe1[0]);
    close(pipe2[1]);

    client(pipe2[0],pipe1[1]);

    int stat;
    while((waitpid(childpid,&stat,0)) == -1){
        if(errno != EINTR){
          stat=-1;
          break;
        }
    }

    return (stat);
}
